package com.fund.com.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fund.com.config.GlobalExceptionHandler;
import com.fund.com.dao.TLikeDao;
import com.fund.com.entity.TLike;
import com.fund.com.service.TLikeService;
import com.fund.utils.PageUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * (TLike)表服务实现类
 *
 * @author makejava
 * @since 2023-02-15 19:42:44
 */
@Service("tLikeService")
public class TLikeServiceImpl extends ServiceImpl<TLikeDao, TLike> implements TLikeService {

    @Override
    public Page<TLike> getPage(Page<TLike> page, TLike tLike) {
        Page<TLike> pageVo = new Page<>(page.getCurrent(), page.getSize() == 0L ? PageUtil.SIZE : page.getSize(), this.count());
        return this.page(pageVo, new QueryWrapper<TLike>(tLike));
    }

    /**
     * 根据名称模糊分页查询，待填入名称
     */
    @Override
    public Page<TLike> getPageLikeName(Page<TLike> page, TLike tLike) {
        Page<TLike> pageVo = new Page<>(page.getCurrent(), page.getSize() == 0L ? PageUtil.SIZE : page.getSize(), this.count());
        return this.page(pageVo, new QueryWrapper<TLike>().like(StringUtils.isNotBlank(""), "", tLike));
    }

    @Override
    public Boolean insertOne(TLike tLike) {
        boolean save = this.save(tLike);
        if (!save) {
            throw new GlobalExceptionHandler("保存失败");
        }
        return true;
    }

    @Override
    public Boolean updateOneById(TLike tLike) {
        boolean b = this.updateById(tLike);
        if (!b) {
            throw new GlobalExceptionHandler("更新失败");
        }
        return true;
    }

    @Override
    public Boolean deleteListByIds(List<String> idList) {
        List<Long> collect = idList.stream().map(f -> Long.parseLong(f)).collect(Collectors.toList());
        boolean b = this.removeByIds(collect);
        if (!b) {
            throw new GlobalExceptionHandler("删除失败");
        }
        return true;
    }

    @Override
    public TLike getOneById(String id) {
        return this.getById(Long.parseLong(id));
    }

    @Override
    public List<TLike> queryAll(TLike tLike) {
        return this.list(new QueryWrapper<TLike>(tLike));
    }
}

